package com.nanfang51g3.ckz.adapter.ext;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.adapter.base.BaseRecyclerViewAdapter;
import com.nanfang51g3.ckz.domain.AccountingBean;
import com.nanfang51g3.ckz.ui.money.withdraw.WithdrawActivity;
import com.nanfang51g3.ckz.utils.NumAnim;

import java.util.List;

/**
 * Created by Administrator on 2016/4/19.
 */
public class AccountingAdapter extends BaseRecyclerViewAdapter<AccountingBean, AccountingAdapter.AccountingViewHolder>/* implements ItemTouchHelperAdapter*/ {

    //    private final OnStartDragListener mDragStartListener;
    public AccountingAdapter(List<AccountingBean> list/*, OnStartDragListener mDragStartListener*/) {
        super(list);
//        this.mDragStartListener = mDragStartListener;
    }


    @Override
    protected void bindDataToItemView(AccountingViewHolder myViewHolder, final AccountingBean item) {

        if (item.getLayoutType() == 0) {
            final Context context = super.getContext();
            //头部
            RelativeLayout relative_accounting = myViewHolder.getView(R.id.relative_accounting);
            TextView accounting_top_total = myViewHolder.getView(R.id.accounting_top_total);
            TextView accounting_top_available_total = myViewHolder.getView(R.id.accounting_top_available_total);
            ImageView iv_accounting_right = myViewHolder.getView(R.id.iv_accounting_right);
            String All_total = item.getAll_total();
            String Deal_total = item.getDeal_total();

            if (super.mList.size() <= 1) {
                iv_accounting_right.setVisibility(View.GONE);
                accounting_top_total.setText("暂无收益");
                accounting_top_available_total.setText("暂无收益");
            } else {
                iv_accounting_right.setVisibility(View.VISIBLE);
                relative_accounting.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String deal_total = item.getDeal_total();
                            context.startActivity(new Intent(context, WithdrawActivity.class).putExtra("deal_total", deal_total));
//                    context.startActivity(new Intent(context, WithdrawActivity.class).putExtra("deal_total", deal_total));
                    }
                });
                //启动数字滚动效果
                NumAnim.startAnim(accounting_top_total, Float.valueOf(item.getAll_total()), 350);
//                NumAnim.startAnim(accounting_top_available_total, Float.valueOf(item.getDeal_total()), 350);
                accounting_top_available_total.setText(item.getDeal_total());
            }
        } else {
            myViewHolder.setText(R.id.accounting_item_title, item.getImage_title());
            myViewHolder.setText(R.id.tv_accounting_item_price, item.getPrice() + "");
            myViewHolder.setText(R.id.accounting_item_time, item.getAdd_time());
            ImageView imageView = myViewHolder.getView(R.id.accounting_item_iv);
            Glide.with(super.getContext()).load(item.getImage())
                    .placeholder(R.mipmap.ic_item)
                    .into(imageView);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return getItem(position).getLayoutType();

    }

    @Override
    public AccountingViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {
        //显示顶部信息
        final AccountingViewHolder view;
        if (type == 0) {
            view = new AccountingViewHolder(inflateItemView(viewGroup, R.layout.accounting_item_top));

            return view;
        } else {
            view = new AccountingViewHolder(inflateItemView(viewGroup, R.layout.accounting_item));


//            view.setOnTouchListener(R.id.accounting_item_iv,new View.OnTouchListener(){
//                @Override
//                public boolean onTouch(View v, MotionEvent event) {
//                    if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
//                        mDragStartListener.onStartDrag(view);
//                    }
//                    return false;
//                }
//            });
            return view;
        }

    }


    public class AccountingViewHolder extends BaseRecyclerViewAdapter.SparseArrayViewHolder {
        public AccountingViewHolder(View itemView) {
            super(itemView);

        }


    }

//    @Override
//    public boolean onItemMove(int fromPosition, int toPosition) {
//        Collections.swap(super.mList, fromPosition, toPosition);
//        notifyItemMoved(fromPosition, toPosition);
//        return true;
//    }
//
//    @Override
//    public void onItemDismiss(int position) {
//        super.mList.remove(position);
//        notifyItemRemoved(position);
//    }
}
